home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-03-11 | 5.8 KB | 240 lines | [TEXT/ALFA] |
-
- ################################################################################
- # Shell routines.
- ################################################################################
-
-
- proc setShellMode {} {
- setTclMode
- changeMode "Csh"
- insertMenu "Tcl"
- }
-
- proc initShell {} {
- insertText "Welcome to Alpha's Tcl shell."
- insertText -w [lindex [winNames] 0] [shellPrompt]
- }
-
- # Return the prompt. We want the window name because some of the commands
- # we evaluate (such as 'edit') open a new window, and we want the insertion
- # to be done in the shell window.
- proc shellPrompt {} {
- regexp "(\[^:\]*):$" [pwd] crDum crDir
- return "\r$crDir> "
- }
-
-
- # Called at all carriage returns.
- proc carriageReturn {} {
- global mode
- global indentOnCR
- set indentString ""
- deleteText [getPos] [selEnd]
- if {$indentOnCR} {
- set pos [getPos]
- set text [getText [lineStart $pos] $pos]
- for {set i 0; set len [string length $text]} {$i <= $len} {incr i} {
- set c [string index $text $i]
- if {($c != "\t") && ($c != "\ ")} {
- set indentString [string range $text 0 [expr $i-1]]
- break
- }
- }
- }
- insertText "\r" $indentString
- }
-
-
- proc tclCarriageReturn {} {
- global mode
- global _text
- global _returnText
- set pos [getPos]
- set ind [string first ">" [getText [lineStart $pos] $pos]]
- if {$ind < 0} {
- carriageReturn
- return
- }
- set lStart [expr [lineStart $pos]+$ind+2]
- endOfLine
- set _text [getText $lStart [getPos]]
- set fileName [lindex [winNames] 0]
- if {[getPos] != [maxPos]} {
- goto [maxPos]
- insertText -w $fileName $_text
- }
- if {[string first "Toolserver" $fileName] != -1} {
- if {![catch {dosc -n ToolServer -s $_text} _returnText]} {
- insertText "\r" $_returnText
- } else {
- insertText "\r"
- }
- mpwPrompt
- } else {
- uplevel #0 {catch $_text _returnText}
- if {[string length $_returnText]} {
- insertText -w $fileName "\r" $_returnText [shellPrompt]
- } else {
- insertText -w $fileName [shellPrompt]
- }
- }
- unset _text
- unset _returnText
- }
- bind '\r' carriageReturn
- bind '\r' tclCarriageReturn "Csh"
- bind '\r' tclCarriageReturn "MPW"
-
- proc startMPW {} {
- global toolserverPath
-
- if {![string length [checkRunning ToolServer MPSX toolserverPath]]} return
-
- insertText "Welcome to Alpha's MPW shell (using ToolServer via AppleEvents)."
- bind '\r' tclCarriageReturn "MPW"
- carriageReturn
- mpwPrompt
- }
- proc mpwPrompt {} {
- insertText "mpw> "
- }
-
- proc setMPWMode {} {
- changeMode "MPW"
- }
-
- # tclCarriageReturn
-
-
-
- #=============================================================================
- # Shell Aliases
- #=============================================================================
-
-
- proc l {args} {
- eval [concat "ls -CF" $args]}
-
- proc ll {args} {
- eval [concat "ls -l" $args]}
-
-
- proc wc {args} {
- set totChars 0
- set totLines 0
- set totWords 0
- set args [glob -nocomplain $args]
- foreach file $args {
- set id [open $file]
- set chars [string length [set text [read $id]]]
- set lines [llength [split $text "\n"]]
- set words [llength [split $text]]
- insertText [format "\r%8d%8d%8d $file" $lines $words $chars]
- set totChars [expr $totChars+$chars]
- set totWords [expr $totWords+$words]
- set totLines [expr $totLines+$lines]
- close $id
- }
- if {[llength $args] > 1} {
- insertText [format "\r%8d%8d%8d total" $totLines $totWords $totChars]
- }
- }
-
- ###########################################################################
- # better-cp-mv.tcl -- modification of your routines, by Mark Nagata
- # for Alpha 5.72, 1/04/94
- ###########################################################################
- proc cp args {
- if {[set len [llength $args]] < 2} {
- error "usage: cp <file1> <file2>\r cp <file1> .... <dir>"
- }
- set len [expr $len-1]
- if {![regexp {.*[^:]} [lindex $args $len] dir]} {
- set dir [string range [lindex $args $len] 1 end]
- }
- if {![regexp {:} $dir] && $dir != ""} {
- set dir [concat :$dir]}
- set args [lreplace $args $len $len]
- set files {}
- foreach arg $args {
- append files " " [glob $arg]
- }
- set report ""
- if {[llength $files] == 1} {
- set f [lindex $files 0]
- if {[file exists $dir]} {
- set targ $dir:[file tail $f]
- append report $f\ ->\ $targ \r
- copyFile $f $targ
- } else {
- append report $f\ ->\ $dir \r
- copyFile $f $dir
- }
- } else {
- foreach f $files {
- set targ $dir:[file tail $f]
- append report $f\ ->\ $targ \r
- if {[catch {copyFile $f $targ} that]} {
- alertnote "Error copying '$f' -> '$targ': $that"
- }
- }
- }
- echo $report
- }
-
- proc mv args {
- if {[set len [llength $args]] < 2} {
- error "usage: mv <file1> <file2>\r mv <file1> .... <dir>"
- }
- set len [expr $len-1]
- if {![regexp {.*[^:]} [lindex $args $len] dir]} {
- set dir [string range [lindex $args $len] 1 end]
- }
- if {![regexp {:} $dir] && $dir != ""} {
- set dir [concat :$dir]}
- set args [lreplace $args $len $len]
- set files {}
- foreach arg $args {
- append files " " [glob $arg]
- }
- set report ""
- if {[llength $files] == 1} {
- set f [lindex $files 0]
- if {[file exists $dir]} {
- set targ $dir:[file tail $f]
- append report $f\ >->\ $targ \r
- moveFile $f $targ
- } else {
- append report $f\ >->\ $dir \r
- moveFile $f $dir
- }
- } else {
- foreach f $files {
- set targ $dir:[file tail $f]
- append report $f\ >->\ $targ \r
- if {[catch {moveFile $f $targ} that]} {
- alertnote "Error moving '$f' -> '$targ': $that"
- }
- }
- }
- echo $report
- }
-
-
- proc rm args {
- set files {}
- foreach arg $args {
- append files " " [glob $arg]
- }
- foreach f $files {
- removeFile $f
- }
- }
-
-
- proc getTypeCreator {f} {
- set l [ls -l $f]
- set len [llength $l]
- list [lindex $l [expr $len-4]] [lindex $l [expr $len-3]]
- }
-